﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using RibbonEditor.AppCode;

namespace RibbonEditor.CommandUIDefinitionClasses
{
    public class UnitAbbreviation : ICommandUIDefinition, IXmlBuildable
    {
        public int? Sequence { get; set; }
        public string Value { get; set; }

        public UnitAbbreviation()
        {}

        public UnitAbbreviation(XmlNode uaXmlNode)
        {
            try
            {
                this.Sequence = XmlHelper.GetNullableIntAttribute(uaXmlNode, "Sequence");
                this.Value = XmlHelper.GetAttribute(uaXmlNode, "Value");
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void AddNode(XmlNode unitXmlNode)
        {
            try
            {
                XmlNode uaXmlNode = XmlHelper.AddNode(unitXmlNode, "UnitAbbreviation");
                XmlHelper.AddAttribute(uaXmlNode, "Sequence", this.Sequence);
                XmlHelper.AddAttribute(uaXmlNode, "Value", this.Value);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void BuildTreeViewElement(TreeNode parentNode)
        {
            try
            {
                TreeNode node = new TreeNode("UnitAbbreviation");
                node.Tag = this;
                node.ContextMenuStrip = ContextMenuStripHelper.BuildUICommandDefContextMenuStrip(node, null, true);

                parentNode.Nodes.Add(node);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
